]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
build: Set up jasmine for unit testing
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 20 Jan 2024 20:04:05 +0000 (21:04 +0100)
committerMarge Bot <marge-bot@gnome.org>
Tue, 21 May 2024 13:42:28 +0000 (13:42 +0000)
Jasmine[0] is a popular testing framework for javascript, which
gjs itself has used in a heavily customized form for its own
unit tests for years.

It's far superior to the very rudimentary `jsUnit` module that
is still included with gjs, and the jasmine-gjs project provides
a general-purpose wrapper for gjs apps.

Set up the necessary build infrastructure to run unit tests
through jasmine. That allows for existing unit tests to be
ported one-by-one.

[0] https://jasmine.github.io/index.html

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>

.gitlab-ci.yml
meson.build
subprojects/jasmine-gjs.wrap [new file with mode: 0644]
tests/meson.build
tests/unit/.eslintrc.yml [new file with mode: 0644]

index 64c290ee9011aad7d333fbd30eadb016546e82a6..8100526922dd8e569cfeb16da5beaf7208f7d75c 100644 (file)
@@ -201,6 +201,7 @@ build:
     paths:
       - mutter
       - build
+      - subprojects/jasmine-gjs
 
 test:
   stage: test
index e54e4c8b60a4c2b78703a8a1f3a50f8e54fab3a6..6eea963491d70f68951897efb12822766dbf33c4 100644 (file)
@@ -293,6 +293,8 @@ if get_option('tests')
   common_test_env.set('GSETTINGS_BACKEND', 'memory')
   common_test_env.set('XDG_CURRENT_DESKTOP', '')
 
+  jasmine = find_program('jasmine')
+
   add_test_setup('default',
     is_default: true,
     env: common_test_env,
diff --git a/subprojects/jasmine-gjs.wrap b/subprojects/jasmine-gjs.wrap
new file mode 100644 (file)
index 0000000..2f6ad0c
--- /dev/null
@@ -0,0 +1,7 @@
+[wrap-git]
+directory=jasmine-gjs
+url=https://github.com/ptomato/jasmine-gjs.git
+revision=c6aa28b3a3b16a3abb53e32825d83f836a2fed42
+
+[provide]
+program_names = jasmine
index 286ad7ab3436f5b8517eedded1cf110fd6b25156..0a3d2d7daa59992ac90ae8b88b0c055b6a02c95c 100644 (file)
@@ -20,6 +20,24 @@ unit_testenv.append('GI_TYPELIB_PATH', shell_typelib_path, separator: ':')
 unit_testenv.append('GI_TYPELIB_PATH', st_typelib_path, separator: ':')
 
 unit_tests = [
+]
+
+foreach test : unit_tests
+  test(test, jasmine,
+    args: [
+      '--module',
+      '--tap',
+      '--no-config',
+      '--interpreter', run_test,
+      'unit/@0@.js'.format(test),
+    ],
+    suite: 'unit',
+    env: unit_testenv,
+    protocol: 'tap',
+    workdir: meson.current_source_dir())
+endforeach
+
+legacy_tests = [
     'highlighter',
     'injectionManager',
     'insertSorted',
@@ -31,7 +49,7 @@ unit_tests = [
     'versionCompare',
 ]
 
-foreach test : unit_tests
+foreach test : legacy_tests
   test(test, run_test,
     args: 'unit/@0@.js'.format(test),
     suite: 'unit',
diff --git a/tests/unit/.eslintrc.yml b/tests/unit/.eslintrc.yml
new file mode 100644 (file)
index 0000000..afe0d9c
--- /dev/null
@@ -0,0 +1,26 @@
+---
+# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+# SPDX-FileCopyrightText: 2024 Florian Müllner <fmuellner@gnome.org>
+rules:
+  jsdoc/require-jsdoc: 'off'
+globals:
+  jasmine: readonly
+  afterAll: readonly
+  afterEach: readonly
+  beforeAll: readonly
+  beforeEach: readonly
+  describe: readonly
+  expect: readonly
+  expectAsync: readonly
+  fail: readonly
+  fdescribe: readonly
+  fit: readonly
+  it: readonly
+  pending: readonly
+  setSpecProperty: readonly
+  setSuiteProperty: readonly
+  spyOn: readonly
+  spyOnAllFunctions: readonly
+  spyOnProperty: readonly
+  xdescribe: readonly
+  xit: readonly